
"""
    自定义异常类
"""


class CoreFieldException(Exception):
    """ 验证字段异常 """

    def __init__(self, field_name):
        self.field_name = field_name

    def __str__(self):
        return self.field_name


def test():
    try:
        a = {"a": 1}
        b = a.get("b")[1]
    except TypeError:
        raise CoreFieldException("msg")


if __name__ == "__main__":
    try:
        res = test()
    except CoreFieldException as e:
        print(f"fail:验证字段'{e}'不存在")